package string;

import java.util.Locale;
import java.util.Random;
import java.util.Scanner;

/**
 * @author Huangjin
 * @version 1.0
 * describe:
 * @date 2023/2/28 14:26
 */
public class VerificationCode {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String num = ran(4);
        System.out.println(num);
        num = num.toUpperCase();
        System.out.println("请输入验证码：");
        String input = sc.next();
        input = input.toUpperCase();
        if (input.equals(num)){
            System.out.println("验证成功！");
        }else {
            System.out.println("验证失败！");
        }
    }
    public static String ran(int len){
        Random r = new Random();
        String c = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String num ="";
        for (int i = 0; i < len; i++) {
            num += c.charAt(r.nextInt(c.length()));
        }
        return num;
    }
}
